﻿var contPrefix = "cartCon";
var contEditPrefix = "cartConEdit";


function createStore(){
	//store = new Persist.Store('applelew');
	
	Store.init();
	
	disPlayCart();
}
function editCart(gcode){
	//alert(contPrefix+gcode);
	new Effect.Opacity(contPrefix+gcode, { from: 1.0, to: 0, duration: 1 });
	
	var hiFunc = hideFunc(gcode);
	window.setTimeout(hiFunc,1000*1);
}

function hideFunc(mcode){
	return function hideEle(){
		//alert($(contPrefix+mcode));
		$(contPrefix+mcode).style.display = 'none';
		Effect.BlindDown(contEditPrefix+mcode,{ duration: 1.0 });
		
	};
}

function showFunc(mcode){
	return function hideEle(){
		//alert(mcode);
		$(contPrefix+mcode).style.display = 'block';
		new Effect.Opacity(contPrefix+mcode, { from: 0, to: 1.0, duration: 1 });
	};
}


function backList(mcode){
	Effect.BlindUp(contEditPrefix+mcode,{ duration: 1.0 });
	var shFunc = showFunc(mcode);
	window.setTimeout(shFunc,1000*1);
}



function disPlayCart(){
	//alert(Persist.type);
	var limit = 4;
	//var goodStr = YAHOO.util.Cookie.get("cProduct");
	var goodStr = "";

		for(var i=0;i<limit;i++){
			//Store.remove("cProduct_"+i);
			var tGStr = Store.get("cProduct_"+i);
			//alert("i:"+i+ " ---> " + tGStr);
			if(tGStr != null)
				goodStr = goodStr + tGStr;
		}
	//alert(goodStr);
	//var result = YAHOO.lang.JSON.parse(goodStr);
	//var goodStr = YAHOO.util.Cookie.get("fdsf");
	if(goodStr == null)
		goodStr = "";
	//alert(goodStr);
	var result = YAHOO.lang.JSON.parse("[" + goodStr + "]");
	//alert(result.length);
	for(var i=0;i<result.length;i++){
		var obj = result[i];
		
		
		var cartConv = document.createElement("div");
		cartConv.id = "cartCon" + i;
	 	cartConv.style.cssText = "clear:both;width:780px;border-bottom:1px solid #cecfce;background-image:url(\"resource/images/common/bg_brand.png\");background-repeat:repeat-y;background-position:left top;";
	
	//alert(cartConv.id);
	 //var cartUl = document.createElement("ul");
	 
	 //here because of ie6 not right
	 //cartUl.class = 'clearfix';
	 cartConv.innerHTML = "<ul class=\"clearfix\"><li class=\"item_brands\"><img src=\"resource/images/common/IconBrands_barior.png\" border=0 /></li>				<li class=\"item_proImg\"><img src=\"resource/products/"+ obj.checkPic +"\" border=0 /></li>				<li class=\"item_proName\">					<div class=\"proNameLnk\"><a class=\"hideAline proname\" href=\"\">"+obj.goodName+"</a></div>					<div class=\"colors_99 proNo\">"+obj.colorId+"</div>				</li>				<li class=\"details_type\">					<div class=\"depad\"><span class=\"colors_99\">颜色：</span>"+obj.colorName+"</div>					<div class=\"depad\"><span class=\"colors_99\">尺码：</span>"+obj.size+"</div>					<div class=\"depad\"><span class=\"colors_99\">单价：</span>￥"+obj.currentPrice+"</div>					<div class=\"depad\"><span class=\"colors_99\">数量：</span>"+obj.num+"</div>				</li>				<li class=\"price_num\">￥ "+obj.currentPrice * obj.num+"</li>				<li class=\"actions_type\">					<div class=\"depad\"><a class=\"hideAline proname\" href=\"#\" onclick=\"editCart('"+i+"')\">修改</a></div>					<div class=\"depad\"><a class=\"hideAline proname\" href=\"\">放入暂存架</a></div>					<div class=\"depad\"><a class=\"hideAline proname\" href=\"\">删除</a></div>				</li></ul>";
	 //cartConv.appendChild(cartUl);
	 $('promotions').parentNode.insertBefore(cartConv,$('promotions'));
	 
	 
	 
	 
	 //cartEdit module
	 var cartConEdit = document.createElement("div");
	 cartConEdit.id = "cartConEdit" + i;
	 cartConEdit.style.cssText = "display:none;width:780px; border-bottom:1px solid #cecfce;background-image:url(\"resource/images/common/bg_editshoppingcart.gif\");";
	 
	 var tColorStr = "";
	 var tSizeStr = "";
	 for(var j=0;j<obj.goodSize.length;j++){
	 	
	 	var sizeStr = "<li><div class=\"sizecode\" onmouseover=\"this.className='sizecodeCur';\" onmouseout=\"this.className='sizecode';\">"+obj.goodSize[j].content+"</div></li>";
	 	tSizeStr = tSizeStr + sizeStr;
	}
	 var colorStr = "<li><img src=\"resource/images/product/c1.gif\" border=0 class=\"ColorImgCur\" onmouseover=\"this.className='ColorImgCur';\" onmouseout=\"this.className='ColorImg';\" /></li>	";
	 
	 
	 cartConEdit.innerHTML = "<table cellpadding=0 cellspacing=0 border=0 class=\"clearfix\">				<tr>					<td class=\"item_brands\" valign=top style=\"padding-bottom:12px;\"><img src=\"resource/images/common/IconBrands_barior.png\" border=0 /></td>					<td class=\"item_EditproImg\" valign=top><img src=\"resource/products/"+obj.listPic+"\" border=0 /></td>					<td class=\"item_Editdetail\" valign=top style=\"padding-bottom:12px;\">						<div id=\"Editproname\"><a href=\"\" class=\"hideAline proname\">"+obj.goodName+"</a></div>				  	<div id=\"Editprocolor\"><span class=\"colors_99\">颜色：</span>"+obj.colorName+"</div>				  	<div id=\"proColorImg\" class=\"clearfix\">					  	<ul class=\"clearfix\">				  </ul>					  </div>					  <div id=\"proPrice\">					  	<ul class=\"clearfix\">							  <li>原价：<span class=\"scline\">￥"+obj.oriPrice+"</span></li>							  <li>现价：<span class=\"nowprice\">￥"+obj.currentPrice+"</span></li>						  </ul>					  </div>					  <div id=\"proSize\">				  	  <div id=\"colorname\">尺码：<span class=\"txttitle\">"+obj.size+"</span></div>					    <div id=\"sizecon\">						    <ul class=\"clearfix\">		"+tSizeStr+"				    </ul>					    </div>					  </div>					</td>					<td class=\"item_Edit\" valign=bottom style=\"padding-bottom:12px;\">						<div><span class=\"colors_99\">颜色：</span>"+obj.colorName+"</div>			      <div><span class=\"colors_99\">尺码：</span>"+obj.size+"</div>			      <div><span class=\"colors_99\">价格：</span>￥"+ obj.currentPrice * obj.num +"</div>			      <div>			      	<span class=\"colors_99\">数量：</span>			      	<select name=\"buyqty\" onchange=\"\" class=\"sltSty\" style=\"width:42px; height:17px; font-size:10px;\">			      		<option value=\"1\" selected>1</option>			      		<option value=\"2\">2</option>			      		<option value=\"3\">3</option>			      		<option value=\"4\">4</option>			      		<option value=\"5\">5</option>			      		<option value=\"6\">6</option>			      		<option value=\"7\">7</option>			      		<option value=\"8\">8</option>			      		<option value=\"9\">9</option>			      		<option value=\"10\">10</option>			      	</select>			      </div>			      <div id=\"item_Editbtn\">			      	<ul class=\"clearfix\">			      		<li class=\"cfm\"><div class=\"confirmedoff\"></div></li>			      		<li class=\"can\" onclick=\"backList('"+i+"')\" ><div class=\"canceloff\" ></div></li>			 		      	</ul>			      </div>				  </td>			  </tr>		  </table>"
	 $('promotions').parentNode.insertBefore(cartConEdit,$('promotions'));
		
	}
	
	
	//alert($('promotions').parentNode.innerHTML);	
	 
}